<template>
	<view class="flex-row-center headerContainer">
		<block v-if="isSearchBar">
			<!-- 搜索栏 -->
			<view class="header" :style="{ position: headerPosition,top:headerTop,opacity: afterHeaderOpacity }">
				<!-- 搜索框 -->
				<view class="input-box">
					<input placeholder="请输入搜索内容" v-model="searchKey" placeholder-style="color:#c0c0c0;"  />
					<view @tap="toSearch()" class="icon pin-icon">search</view>
				</view>

			</view>
			<!-- 占位 -->
		</block>
		<block v-else>
			<!-- 普通顶栏栏 -->
			<view class="header" :style="{ position: headerPosition,top:headerTop,opacity: afterHeaderOpacity }">
				<view @click="goBack">返回</view>
				<view class="title"> {{title}} </view>
			</view>
		</block>
		<view class="place"></view>
	</view>
</template>

<script>
	//高德SDK
	// import amap from '@/common/SDK/amap-wx.js';
	export default {
		props: ['isSearchBar', 'hasBack', 'title'],
		data() {
			return {
				afterHeaderOpacity: 1, //不透明度
				headerPosition: 'fixed',
				headerTop: 0,
				statusTop: null,
				searchKey:'',
			};
		},
		onLoad() {
			this.statusHeight = plus.navigator.getStatusbarHeight();
			
		},
		methods: {
			//消息列表
			toMsg() {
				uni.navigateTo({
					url: '/pages/message/messages'
				})
			},	
			
			toQR(){
				uni.navigateTo({
					url:'/pages/QRCode/QRCode'
				})
			},
			//搜索跳转
			toSearch() {
				// uni.showToast({
				// 	title: '建议跳转到新页面做搜索功能'
				// });
				console.log("search")
				this.$emit('search',{key:this.searchKey})
			},
			goBack() {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	
	.headerContainer{
		
		background-color: white;
		width: 100%;
	}
	

	.icon {
		font-size: 60upx;
		font-style: normal;
		color: #000000;
	}

	.status {
		width: 100%;
		height: 0;
		position: fixed;
		z-index: 10;
		background-color: #fff;
		top: 0;


	}

	.header {
		width: 100%;
		padding: 0 4%;
		box-sizing: border-box;
		height: 100upx;
		display: flex;
		align-items: center;
		position: fixed;
		top: 0;
		z-index: 10;
		background-color: #FFFFFF;
	
		.addr {
			width: 120upx;
			height: 60upx;
			flex-shrink: 0;
			display: flex;
			align-items: center;
			font-size: 28upx;
			color: $pin-color-foreground;

			.icon {
				height: 60upx;
				margin-right: 5upx;
				display: flex;
				align-items: center;
				font-size: 42upx;
				color: $pin-color-foreground;
			}
		}

		.input-box {
			width: 100%;
			height: 60upx;
			background-color: #f5f5f5;
			border-radius: 10upx;
			position: relative;
			display: flex;
			align-items: center;

			.icon {
				display: flex;
				align-items: center;
				position: absolute;
				top: 0;
				right: 0;
				width: 60upx;
				height: 60upx;
				font-size: 34upx;
				color: #c0c0c0;
			}

			input {
				padding-left: 28upx;
				height: 28upx;
				font-size: 28upx;
			}
		}

		.icon-btn {
			width: 100rpx;
			height: 45rpx;
			// flex-shrink: 0;
			display: flex;
			justify-content: center;
			align-items: center;

			.icon {
				width: 34rpx;
				height: 35rpx;
				// display: flex;
				// justify-content: flex-end;
				// align-items: center;
				// font-size: 42upx;
			}
		}
	}

	.place {
		background-color: #ffffff;
		height: 100upx;
	
	}
</style>
